<template>
	<view class="user pageBg">
		<view :style="{height: getNavBarHeight() + 'px' }">
			
		</view>
		<view class="userInfo">
			<view class="avator">
				<image class="pic" src="../../static/images/xxmLogo.png" mode="aspectFill"></image>
			</view>
			<view class="ip">
				{{ userInfo && userInfo.IP }}
			</view>
			<view class="from">
				来自：{{userInfo && (userInfo.address.city || userInfo.address.province || userInfo.address.country )}}
			</view>
		</view>
		<view class="section">
			<view class="list">
				<view class="row" @click="handleNavigator('download')">
					<view class="left">
						<uni-icons type="download-filled" size="20" color="#28B389"></uni-icons>
						<text class="text">我的下载</text>
					</view>
					<view class="right">
						<text class="text">{{ userInfo && userInfo.downloadSize }}</text>
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
				<view class="row" @click="handleNavigator('score')">
					<view class="left">
						<uni-icons type="star-filled" size="20" color="#28B389"></uni-icons>
						<text class="text">我的评分</text>
					</view>
					<view class="right">
						<text class="text">{{ userInfo && userInfo.scoreSize }}</text>
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
				<view class="row">
					<view class="left">
						<uni-icons type="chatboxes-filled" size="20" color="#28B389"></uni-icons>
						<text class="text">联系客服</text>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
					<!-- 条件编辑  小程序 -->
					<!-- #ifdef MP -->
					<button open-type="contact">联系客服</button>
					<!-- #endif -->
					<!-- 条件编辑  非小程序 -->
					<!-- #ifndef MP -->
					<button @click="onContact">联系客服</button>
					<!-- #endif -->
				</view>
			</view>
		</view>
		<view class="section">
			<view class="list">
				<view class="row" @click="handleNotice('653507c6466d417a3718e94b')">
					<view class="left">
						<uni-icons type="notification-filled" size="20" color="#28B389"></uni-icons>
						<text class="text">订阅更新</text>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
				<view class="row" @click="handleNotice('6536358ce0ec19c8d67fbe82')">
					<view class="left">
						<uni-icons type="flag-filled" size="20" color="#28B389"></uni-icons>
						<text class="text">常见问题</text>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { getNavBarHeight } from '@/utils/system.js'
import { userInfoApi } from '@/api/apis.js'
import { ref } from 'vue'

const userInfo = ref(null)

const handleNotice = (id) => {
	uni.navigateTo({
		url: '/pages/notice/detail?id=' + id
	})
}

const handleNavigator = (type) => {
	let name;
	if(type === 'download') {
		name = '我的下载'
	}
	if(type == 'score') {
		name = '我的评分'
	}
	uni.navigateTo({
		url: "/pages/classlist/classlist?name=" + name + '&type=' + type
	})
}

const onContact = () => {
	uni.makePhoneCall({
		phoneNumber: "144"
	})
}

const getUserInfo = async () => {
	const res = await userInfoApi()
	userInfo.value = res.data
}

getUserInfo()
</script>

<style lang="scss" scoped>
.user {
	.userInfo {
		width: 690rpx;
		margin: 30rpx 0 80rpx 0;
		display: flex;
		flex-direction: column;
		align-items: center;
		.avator {
			width: 170rpx;
			height: 170rpx;
			border-radius: 50%;
			overflow: hidden;
			.pic {
				width: 100%;
				height: 100%;
			}
		}
		.ip {
			font-size: 42rpx;
			padding: 15rpx 0;
			color: #333;
		}
		.from {
			color: #aaa;
		}
	}
	.section {
		width: 690rpx;
		margin: 50rpx auto;
		border: 1rpx solid #eee;
		border-radius: 10rpx;
		box-shadow: 0 0 30rpx rgba(0, 0, 0, 0.08);
		.list {
			.row {
				width: 100%;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 100rpx;
				padding: 0 20rpx;
				border-bottom: 1rpx solid #eee;
				background-color: #fff;
				position: relative;
				&:last-child {
					border: none;
				}
				.left {
					display: flex;
					align-items: center;
					.text {
						color: #666;
						margin-left: 20rpx;
					}
				}
				.right {
					display: flex;
					align-items: center;
					.text {
						color: #aaa;
						font-size: 28rpx;
						margin-right: 10rpx;
					}
				}
				button {
					position: absolute;
					top: 0;
					left: 0;
					width: 100%;
					height: 100%;
					opacity: 0;
				}
			}
		}
	}
}
</style>
